package com.choosefine.it.company.controller;


import com.choosefine.it.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.basedata.service.FinishPhotoService;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.company.model.CompanyProjectExperience;
import com.choosefine.it.company.model.vo.CompanyProjectExperienceVO;
import com.choosefine.it.company.service.CompanyProjectExperienceService;
import com.github.pagehelper.Page;

/**
 * 建筑公司-项目经验
 * @author chenjian
 * @date 2016-12-7 下午2:18:28
 */
@RestController
@RequestMapping("/companyProjectExperience")
@Api(value="建筑公司项目经验",description="陈健")
public class CompanyProjectExperienceController extends BaseController{
	@Autowired
	private CompanyProjectExperienceService companyProjectExperienceService;
	
	@Autowired
	private FinishPhotoService finishPhotoService;
	
	Logger logger=LoggerFactory.getLogger(CompanyProjectExperienceController.class);
	@ApiOperation(value = "建筑公司-项目经验", notes = "",response=CompanyProjectExperienceVO.class)
	@ApiImplicitParams({@ApiImplicitParam(name = "userCode", value = "用户编号", required = true, dataType = "String",paramType = "path"),
			@ApiImplicitParam(name = "pageNum", value = "起始行", required = true, dataType = "Integer", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "Integer", paramType = "query")})
	@RequestMapping(value="/getCompanyProjectExperienceList/{userCode}",method=RequestMethod.GET,produces="application/json")
	public String getCompanyProjectExperienceList(@PathVariable String userCode,Integer pageNum,Integer pageSize){
		String result=null;
		PageDTO page= new PageDTO();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		if(StringUtils.isNotBlank(userCode)){
			Page<CompanyProjectExperienceVO> list = companyProjectExperienceService.findeCompanyProjectExperienceList(userCode, page);
			//获取项目经验总数
			int projectCount = companyProjectExperienceService.findeProjectExperienceCount(userCode);
			if(list.size()>0){
				for(CompanyProjectExperienceVO companyProjectExperienceVO:list){
					List<String> finishPhotoList=finishPhotoService.findByProjectCode(companyProjectExperienceVO.getProjectCode());
					companyProjectExperienceVO.setFinishPhotoes(finishPhotoList);
					companyProjectExperienceVO.setProjectCount(projectCount);
				}
				result= responseSuccess(list);
			}else{
				result= responseFail(ResultCode.FAILED,ResultCode.MSG_DATA_ISEMPTY);
			} 
		}else{
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_PARAMS_NULL);
		}
		return result;
	}
	
	@ApiOperation(value = "建筑公司-添加项目经验", notes = "")
	@RequestMapping(value="/saveCompanyProjectExperience",method=RequestMethod.POST)
	public String saveCompanyProjectExperience(@RequestBody CompanyProjectExperience companyProjectExperience){
		String result=null;
		companyProjectExperience.setCtime(DateUtils.getNowTime());
		Integer isSuccess=companyProjectExperienceService.saveCompanyProjectExperience(companyProjectExperience);
		if(isSuccess!=null&&isSuccess.intValue()>0){
			result= responseSuccess(isSuccess, ResultCode.SUCCESS,ResultCode.MSG_SUCCESS);
		}else {
			result= responseFail(ResultCode.FAILED,ResultCode.MSG_DATA_ISEMPTY);
		}
		return result;
	}
	
}
